package com.yylany.controller;

import com.yylany.emunt.CommonConstants;
import com.yylany.page.PageData;
import com.yylany.page.PageParams;
import com.yylany.pojo.Agency;
import com.yylany.pojo.House;
import com.yylany.pojo.User;
import com.yylany.service.AgencyService;
import com.yylany.service.HouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class AgencyController {

    @Autowired
    private AgencyService agencyService;

    @Autowired
    private HouseService houseService;


    @RequestMapping("agency/create")
    public String agencyCreate() {

        return "/user/agency/create";
    }


    @RequestMapping("/agency/agentList")
    public String agentList(Integer pageSize, Integer pageNum, ModelMap modelMap) {

        if (pageSize == null) {
            pageSize = 6;
        }
        PageData<User> ps = agencyService.getAllAgent(PageParams.build(pageSize, pageNum));
        List<House> houses =  houseService.getHotHouse(CommonConstants.RECOM_SIZE);
        modelMap.put("recomHouses", houses);
        modelMap.put("ps", ps);

        return "/user/agent/agentList";
    }

    @RequestMapping("/agency/agentDetail")
    public String agentDetail(Long id, ModelMap modelMap) {

        return "/user/agent/agentDetail";
    }

    @RequestMapping("/agency/agentMsg")
    public String agentMsg(Long id, String msg, String name, String email, ModelMap modelMap) {

        return "";
    }

    @RequestMapping("/agency/agencyDetail")
    public String agencyDetail(Integer id, ModelMap modelMap) {

        return "/user/agency/agencyDetail";
    }


    @RequestMapping("agency/list")
    public String agencyList(ModelMap modelMap) {

        List<Agency> agencies = agencyService.getAllAgency();
        List<House> houses = houseService.getHotHouse(CommonConstants.RECOM_SIZE);
        modelMap.put("recomHouses", houses);
        modelMap.put("agencyList", agencies);
        return "/user/agency/agencyList";
    }

    @RequestMapping("agency/submit")
    public String agencySubmit(Agency agency) {

//        return "redirect:/index?" + ResultMsg.successMsg("创建成功").asUrlParams();
        return "";
    }


}
